package cn.tedu.tnt_sky.controller.admin;

import cn.tedu.tnt_sky.common.result.PageResult;
import cn.tedu.tnt_sky.common.result.Result;
import cn.tedu.tnt_sky.pojo.dto.AdminUserPageDTO;
import cn.tedu.tnt_sky.pojo.dto.AdminUserUpdateDTO;
import cn.tedu.tnt_sky.service.AdminUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@Slf4j
@RestController
@RequestMapping("/tnt/users")
@Api(tags = "用户管理相关接口")
public class UserListController {
    @Autowired
    AdminUserService adminUserService;

    @ApiOperation(value="实现分页功能")
    @GetMapping("/page")
    public Result<PageResult> page(AdminUserPageDTO adminPageDTO){
        log.info("用户管理分页查询：{}",adminPageDTO);
        PageResult pageResult = adminUserService.pageQuery(adminPageDTO);
        return Result.success(pageResult);
    }

    /**
     * 修改用户数据
     * @param adminUserUpdateDTO
     * @return
     */
    @ApiOperation(value="修改用户数据")
    @PutMapping("/update")
    public Result update(@RequestBody AdminUserUpdateDTO adminUserUpdateDTO){
        log.info("修改用户数据:{}",adminUserUpdateDTO);
        adminUserService.update(adminUserUpdateDTO);
        return Result.success();
    }

    @ApiOperation(value="删除用户")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable String id){
        log.info("删除用户，ID为{}",id);
        adminUserService.delete(id);
        return Result.success();
    }
}
